package com.dailyblue.java.cloud.config;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.ConfigurableApplicationContext;

import java.util.concurrent.TimeUnit;

@SpringBootApplication
public class SpringcloudNacosConfig8033Application {

    public static void main(String[] args) throws Exception {
        ConfigurableApplicationContext applicationContext = SpringApplication.run(SpringcloudNacosConfig8033Application.class, args);
        while (true) {
            //当动态配置刷新时，会更新到 Enviroment中，因此这里每隔一秒中从Enviroment中获取配置
            String name = applicationContext.getEnvironment().getProperty("user.name");
            String age = applicationContext.getEnvironment().getProperty("user.age");
            String sex = applicationContext.getEnvironment().getProperty("user.sex");
            System.err.println("user name :" + name + "; age: " + age + ";sex：" + sex);
            String stuname = applicationContext.getEnvironment().getProperty("student.name");
            String stuage = applicationContext.getEnvironment().getProperty("student.age");
            System.out.println("stu name:"+stuname+"\tage:"+stuage);
            String zn = applicationContext.getEnvironment().getProperty("zhuoyue.name");
            String za = applicationContext.getEnvironment().getProperty("zhuoyue.age");
            String zs = applicationContext.getEnvironment().getProperty("zhuoyue.sex");
            System.out.println("zhuoyue name:"+zn+"\tage:"+za+"\tsex:"+zs);
            TimeUnit.SECONDS.sleep(5);
        }

    }

}
